package com.taxi.driver.module.main.mine.help.feedback;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qianxx.adapter.SuperAdapter;
import com.qianxx.adapter.internal.SuperViewHolder;
import com.taxi.driver.R;
import com.taxi.driver.module.vo.FeedbackVO;
import com.taxi.driver.util.TimeUtils;

import java.util.ArrayList;

public class FeedbackAdapter extends SuperAdapter<FeedbackVO> {
    private int openIndex = -1;

    public FeedbackAdapter(Context context) {
        super(context, new ArrayList<FeedbackVO>(), R.layout.item_feedback);
    }

    @Override
    public void onBind(SuperViewHolder holder, int viewType, int position, FeedbackVO item) {
        holder.setText(R.id.tv_tilte,item.content);
        holder.setText(R.id.tv_content,item.content);
        holder.setText(R.id.tv_time, TimeUtils.paseDate(item.createTime));
        TextView tv_statue=(TextView) holder.getView(R.id.tv_statue);
        TextView tv_reply=(TextView) holder.getView(R.id.tv_reply);
        RelativeLayout rl=holder.getView(R.id.rl);
        LinearLayout ll=holder.getView(R.id.ll);
        if(!TextUtils.isEmpty(item.reply)){
            tv_statue.setText(getContext().getResources().getString(R.string.raplyed));
            tv_reply.setVisibility(View.VISIBLE);
            tv_reply.setText(getContext().getResources().getString(R.string.reply)+item.reply);
        }else{
            tv_statue.setText("");
            tv_reply.setVisibility(View.GONE);
            tv_reply.setText("");
        }

        ImageView iv_nav=(ImageView)holder.getView(R.id.iv_nav);
        if(openIndex == position && !item.isOpen){
            ll.setVisibility(View.VISIBLE);
            iv_nav.setRotation(-90);
            item.isOpen = true;
        }else{
            ll.setVisibility(View.GONE);
            iv_nav.setRotation(90);
            item.isOpen = false;
        }

        rl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                openIndex = position;
                notifyDataSetChanged();
            }
        });

    }
}
